package edu.uic.ids517.servlet;

import java.io.*;

import javax.servlet.*;
import javax.servlet.http.*;

import edu.uic.ids517.model.DatabaseAccessBean;

public class LogoutServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 

		System.out.println("LogoutServlet");
		HttpSession session = request.getSession();
		String nextUrl="";
		String action = request.getParameter("session"); 

		if(action.equalsIgnoreCase("Logout"))
		{ 
			nextUrl = "/LogOutSuccess.jsp";	
			DatabaseAccessBean dbase = (DatabaseAccessBean)session.getAttribute("dbaseBean");
			if(dbase != null){
				dbase.closeConnection();
				session.invalidate();
			}		
		}

		if(action.equalsIgnoreCase("Cancel"))
		{ 
			nextUrl = "/mainMenu.jsp";	

		}

		RequestDispatcher dispatcher = request.getRequestDispatcher(nextUrl); 
		dispatcher.forward(request, response); 
	}
}

